package myky.com.doctorapp.presenter;

import io.reactivex.disposables.Disposable;
import myky.com.doctorapp.api.ResponseTransformer;
import myky.com.doctorapp.api.schedulers.SchedulerHelper;
import myky.com.doctorapp.base.BasePresenterIm;
import myky.com.doctorapp.base.SimpleSubscribe;
import myky.com.doctorapp.entity.HealthRecordEntity;
import myky.com.doctorapp.contract.ExperConsultContract;
import myky.com.doctorapp.entity.LastConsultEntity;
import myky.com.doctorapp.model.ExperConsultModel;

public class ExperConsultPresenter extends BasePresenterIm<ExperConsultContract.View> implements ExperConsultContract.Presenter {

    ExperConsultModel experConsultModel;

    public ExperConsultPresenter() {
        experConsultModel = new ExperConsultModel();
    }

    @Override
    public void findHealthRecord() {
        experConsultModel.findHealthRecord()
                .compose(ResponseTransformer.handleResult())
                .compose(SchedulerHelper.applySchedulers())
                .subscribe(new SimpleSubscribe<HealthRecordEntity>() {
                    @Override
                    protected void onSuccess(HealthRecordEntity healthRecordEntity) {
                        HealthRecordEntity.PerProfileBean perProfile = healthRecordEntity.getPerProfile();

                        if (perProfile != null) {

                            mView.showHealthRecord(healthRecordEntity.getPerProfile());

                        }

                    }

                    @Override
                    protected void onFailed(String msg) {

                        mView.logCat(msg);

                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                        addSubscription(d);

                    }
                });

    }

    @Override
    public void findLastConsultContent(String doctorID, String fillType, String version) {

        experConsultModel.findLastConsultContent(doctorID, fillType, version)
                .compose(ResponseTransformer.handleResult())
                .compose(SchedulerHelper.applySchedulers())
                .subscribe(new SimpleSubscribe<LastConsultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                        addSubscription(d);

                    }

                    @Override
                    protected void onSuccess(LastConsultEntity lastConsultEntity) {

                        if(lastConsultEntity!=null){
                            mView.showLastConsultContent(lastConsultEntity);
                        }

                    }

                    @Override
                    protected void onFailed(String msg) {
                        mView.logCat(msg);

                    }
                });

    }
}
